package com.zhai.test.domain;

import com.zhai.domain.strategy.service.armory.IStrategyArmory;
import com.zhai.domain.strategy.service.armory.IStrategyDispatch;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

/**
 * @Description: 策略装配测试类
 * @ClassName: StrategyTest
 * @Author: zhaiyongxin
 * @Date: 2024/12/31 14:25
 * @Version: 1.0
 */
@SpringBootTest
@Slf4j
@RunWith(SpringRunner.class)
public class StrategyTest {

    @Resource
    private IStrategyDispatch strategyDispatch;
    @Resource
    private IStrategyArmory strategyAmory;

    /**
     * 测试策略装配
     */
    @Before
    public void test_assembleLotteryStrategy(){
        /**
         * 该方法执行如下操作
         * 1.初始化装配所有策略：每个奖品占用的区域大小，并且会进行顺序打乱
         * 2.如果该策略存在权重规则配置：
         *  2.1 查询权重策略列表
         *  2.2 按照权重策略列表进行排除，每个积分范围能抽取的奖品范围不同
         *  2.3 根据权重策略列表进行装配
         */
        strategyAmory.assembleLotteryStrategy(Long.valueOf("100001"));
    }

    /**
     * 测试抽奖
     */
    @Test
    public void test_getRandomAwardId(){
        for (int i = 0; i < 100; i++) {
            log.info("测试结果：{} - 奖品ID值", strategyDispatch.getRandomAwardId(100001L));
        }
    }

    /**
     * 根据策略ID+权重值，从装配的策略中随机获取奖品ID值
     */
    @Test
    public void test_getRandomAwardId_ruleWeightValue() {
        log.info("测试结果：{} - 4000 策略配置", strategyDispatch.getRandomAwardId(100001L, "4000:102,103,104,105"));
        log.info("测试结果：{} - 5000 策略配置", strategyDispatch.getRandomAwardId(100001L, "5000:102,103,104,105,106,107"));
        log.info("测试结果：{} - 6000 策略配置", strategyDispatch.getRandomAwardId(100001L, "6000:102,103,104,105,106,107,108,109"));
    }
}
